<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%# encoding:utf-8 %>
<html>
<head>
<title>HappyERP</title>
<!--<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />-->
<%= stylesheet_link_tag "images" %>

<%= stylesheet_link_tag "/javascripts/ext422/resources/css/ext-all.css" %>
<%= stylesheet_link_tag "ext-patch.css" %>

<%= javascript_include_tag "ext422/ext-all.js" %>
<%= javascript_include_tag "ext422/locale/ext-lang-zh_CN.js" %>

<%= javascript_include_tag "LodopFuncs.js" %>
<object id="LODOP" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
  <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
</object>

<%= csrf_meta_tag %>

<script type="text/javascript">
    //提示未安装打印插件
    var LODOP = getLodop(document.getElementById('LODOP'), document.getElementById('LODOP_EM'));

    Ext.require([
        'Ext.grid.*',
        'Ext.data.*',
        'Ext.util.*',
        'Ext.state.*',
        'Ext.form.*',
        'Ext.layout.*',
        'Ext.tree.*',
        'Ext.tab.Panel',
        'Ext.selection.CellModel'
    ]);

    var authToken = Ext.create('Ext.form.field.Hidden', {
        name: 'authenticity_token',
        value: '<%=Rack::Utils.escape_html(form_authenticity_token)%>'
    });

    //rejectKeyArray是个比较通用的排除数组，一般的提交都不需要提交这些信息
    var rejectKeyArray = new Array();
    rejectKeyArray.push('product_name');
    rejectKeyArray.push('is_suit');
    rejectKeyArray.push('number');
    rejectKeyArray.push('spec');
    rejectKeyArray.push('unit');
    var financialManagement = "<%=session[:financial_management]%>";
    //Ext.QuickTips.init();
    //Ext.lib.Ajax.defaultPostHeader += ";charset=UTF-8";
    Ext.data.Connection.prototype.method = 'GET';

    // Add the additional 'advanced' VTypes
    Ext.apply(Ext.form.field.VTypes, {
        daterange: function (val, field) {
            var date = field.parseDate(val);

            if (!date) {
                return false;
            }
            if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
                var start = field.up('form').down('#' + field.startDateField);
                start.setMaxValue(date);
                start.validate();
                this.dateRangeMax = date;
            }
            else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
                var end = field.up('form').down('#' + field.endDateField);
                end.setMinValue(date);
                end.validate();
                this.dateRangeMin = date;
            }
            /*
             * Always return true since we're only using this vtype to set the
             * min/max allowed values (these are tested for after the vtype test)
             */
            return true;
        },

        daterangeText: 'Start date must be less than end date',

        password: function (val, field) {
            if (field.initialPassField) {
                var pwd = field.up('form').down('#' + field.initialPassField);
                return (val == pwd.getValue());
            }
            return true;
        },

        passwordText: 'Passwords do not match'
    });

    function logout() {
        Ext.Ajax.request({
            url: '/index/logout',
            success: function (result, request) {
                window.document.location.href = '/index/login';
            },
            failure: function (result, request) {
                Ext.MessageBox.show({
                    title: '消息',
                    msg: "通讯失败，请从新操作",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                });
            },
            method: 'GET'
        });
    }

    //Extjs 4.0

    var accordition = Ext.create('Ext.panel.Panel', {
        region: 'west',
        margins: '5 0 5 5',
        split: true,
        width: 140,
        collapseMode: 'mini',
        layout: 'accordion'
    });

    //EXTJS 4
    var workTabs = Ext.create('Ext.tab.Panel', {
        region: 'center',
        autoScroll: true,
        autoWidth: true,
        //ADD: handler
        onTitleDbClick: function (e, target, o) {
            accordition.toggleCollapse(true);
        }
    });

    var sysMsgButton = Ext.create('Ext.Button', {
        scope: this,
        text: '系统消息',
        iconCls: 'msg',
        handler: function () {
            if (workTabs.items.get(1) == undefined) {

                workTabs.add({
                    title: '系统消息',
                    autoLoad: {
                        url: '/sys_msg/sysMsgList',
                        scripts: true
                    },
                    closable: true
                }).show();

            } else {
                workTabs.setActiveTab(1);
                workTabs.getActiveTab().getLoader().load({
                    url: '/sys_msg/sysMsgList',
                    scripts: true
                });
                //workTabs.getItem(0).getUpdater().update(url);
                workTabs.getActiveTab().show();
            }
        }
    })

    function synUnreadSysMsg() {
        Ext.Ajax.request({
            url: '/sys_msg/getUnreadSysMsgsSize',
            success: function (result, request) {
                if (parseInt(result.responseText) > 0) {
                    sysMsgButton.setText("系统消息<em style=color:red>(" + parseInt(result.responseText) + ")</em>");
                } else {
                    sysMsgButton.setText('系统消息');
                }
            },
            failure: function (result, request) {
            },
            method: 'GET'
        });
    }

    //var synUnreadSysMsg = null;

    Ext.onReady(function () {
        Ext.util.Format.decimalSeparator = '.';
        Ext.util.Format.thousandSeparator = ',';

        var logoutButton = Ext.create('Ext.Button', {
            text: '退出系统',
            iconCls: 'exit',
            handler: function () {
                Ext.Ajax.request({
                    url: '/index/logout',
                    success: function (result, request) {
                        window.document.location.href = '/index/login';
                    },
                    failure: function (result, request) {
                        Ext.MessageBox.show({
                            title: '消息',
                            msg: "通讯失败，请从新操作",
                            buttons: Ext.MessageBox.OK,
                            icon: Ext.MessageBox.WARNING
                        });
                    },
                    method: 'GET'
                });
            }
        })

        var topPanel = Ext.create('Ext.panel.Panel', {
            bbar: ['<b style="font-size:14px;"><%=@companyNameAB%>， 您好：<%=session[:employee_name]%>  (<%=session[:role].name%>)', '->', '-', sysMsgButton, '-', logoutButton],
            region: 'north'
        });


        //Extjs 4
        var reminderPanel = Ext.create('Ext.panel.Panel', {
            title: '系统提醒',
            id: 'reminder_panel',
            //html: '&lt;empty panel&gt;',
            //cls:'cellpadding:10',

            //bodyStyle: 'padding:15px;align:center',
            listeners: {
                //expand: showAgileDiagram
            },
            loader: {}
        });

        workTabs.add(reminderPanel).show();

        workTabs.openTab = function (node) {
            // var id = node.attributes.url;
            var id = node.attributes.url;
            var url = node.attributes.url;
            var tabTitle = node.text;
            var titleStyle = ['background:url(\'', node.ui.getIconEl().src, '\') no-repeat; padding-left:20px'].join('');

            workTabs.getItem(0).setTitle(tabTitle);
            workTabs.getItem(0).load({
                url: url,
                scripts: true
            });
            //workTabs.getItem(0).getUpdater().update(url);
            workTabs.getItem(0).show();
        };

        var viewport = Ext.create('Ext.container.Viewport', {
            layout: 'border',
            items: [topPanel, accordition, workTabs]
        });

        //添加详细菜单
        function renderMenu() {
            var menus = eval(<%=raw @menus%>);
            if (!menus) {
                return;
            }
            for (var i = 0; i < menus.length; i++) {
                var itemModuleMenu = menus[i];
                var title = "<div style='background:url(" + itemModuleMenu.image +
                        ") no-repeat;padding-left:20px;'>" +
                        itemModuleMenu.name +
                        "</div>";
                //Extjs 4,模级菜单
                var moduleNode = Ext.create('Ext.tree.Panel', {
                    title: title,
                    rootVisible: false,
                    lines: false,
                    autoScroll: true,
                    qtips: itemModuleMenu.qitps,
                    root: {
                        editable: false,
                        expanded: true,
                        text: itemModuleMenu.name,
                        draggable: false,
                        children: itemModuleMenu.children
                    },
                    listeners: {
                        itemclick: {
                            //Ext.view.View this, Ext.data.Model record, HTMLElement item, Number index, Ext.EventObject e, Object options
                            fn: function (view, record, item, index, e, options) {
                                workTabs.items.first().setTitle(record.data.text);
                                //var tab = workTabs.getActiveTab();
                                //var loader = workTabs.getActiveTab().getLoader();
                                workTabs.setActiveTab(0);
                                workTabs.getActiveTab().getLoader().load({
                                    url: record.data.id,
                                    scripts: true
                                });
                                //workTabs.getItem(0).getUpdater().update(url);
                                workTabs.getActiveTab().show();
                            }
                        }
                    }
                });
                accordition.add(moduleNode);
            }
            accordition.doLayout();
        }

        renderMenu();
        //Extjs 4
        //
        var task = {
            run: function () {
                synUnreadSysMsg();
                //alert(1);
            },
            interval: 900000//900000 //1 second
        }
        Ext.TaskManager.start(task);


        //定义模型
        //为部门的combobox定义模型
        Ext.define('DeptCBB', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'department_id', type: 'int', mapping: 'id'},
                {name: 'number', type: 'string'},
                {name: 'name', type: 'string'}
            ]
        });

        departmentStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'DeptCBB',
            proxy: {
                type: 'ajax',
                url: '/department/getAllDepartments?for_cbb=true',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            autoLoad: true
        });


        //产品下拉框模型
        Ext.define('ProductCBB', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'number', type: 'string'},
                {name: 'name', type: 'string'},
                {name: 'spec'},
                {name: 'unit'},
                {name: 'unit_price'},
                {
                    name: 'is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                }
            ]
        });

        productStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'ProductCBB',
            proxy: {
                type: 'ajax',
                url: '/product/getAllProducts?for_cbb=true_simple',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            }
        });

        productAllInfoStore = Ext.create('Ext.data.Store', {
            autoDestroy: true,
            model: 'ProductCBB',
            proxy: {
                type: 'ajax',
                url: '/product/getAllProducts',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            }
        });


        //客户下拉框模型
        Ext.define('Customer', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'name', type: 'string'},
                {
                    name: 'number',
                    convert: function (value, record) {
                        if (value === "") {
                            return "未设置编号"
                        } else {
                            return value;
                        }
                    }
                },
                {name: 'linkman'},
                {name: 'phone'},
                {name: 'address'},
                {name: 'customer_type_id', type: 'int'},
                {
                    name: 'customer_type_name',
                    mapping: 'customer_type',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'fax'},
                {name: 'email'},
                {name: 'description'},
                {name: 'adder',
                    mapping: 'adder',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'editor',
                    mapping: 'editor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'bank'},
                {name: 'bank_account'},
                {name: 'created_at'},
                {name: 'is_locked'},
                {name: 'updated_at'}
            ]
        });

        customerStore = Ext.create('Ext.data.Store', {
            autoDestroy: true,
            autoSync: true,
            model: 'Customer',
            proxy: {
                type: 'ajax',
                url: '/customer/getAllCustomers?for_cbb=true',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            pageSize: 1000,//default:25
            autoLoad: true
        });

        customerAllInfoStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'Customer',
            autoSync: true,
            proxy: {
                type: 'ajax',
                url: '/customer/getAllCustomers',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            pageSize: 1000,//default:25
            autoLoad: true
        });

        companyAllInfoStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'Customer',
            autoSync: true,
            proxy: {
                type: 'ajax',
                url: '/company/getAllCompanies',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            pageSize: 1000,//default:25
            autoLoad: true
        });

        //客户下拉框模型
        Ext.define('Vendor', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'name', type: 'string'},
                {
                    name: 'number',
                    convert: function (value, record) {
                        if (value === "") {
                            return "未设置编号"
                        } else {
                            return value;
                        }
                    }
                },
                {name: 'linkman'},
                {name: 'email'},
                {name: 'bank'},
                {name: 'bank_account'},
                {name: 'phone'},
                {name: 'fax'},
                {name: 'address'},
                {name: 'description'},
                {name: 'is_locked'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        vendorStore = Ext.create('Ext.data.Store', {
            autoDestroy: true,
            autoSync: true,
            model: 'Vendor',
            proxy: {
                type: 'ajax',
                url: '/vendor/getAllVendors?for_cbb=true',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            pageSize: 1000,//default:25
            autoLoad: true
        });

        //客户下拉框模型
        Ext.define('CustomerType', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'name', type: 'string'},
                {name: 'is_locked'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        Ext.define('CompanyModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'name', type: 'string'}
            ]
        });

        //仓库下拉框模型
        Ext.define('Warehouse', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'company_name', mapping: 'company', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }},
                {name: 'company_id'},
                {name: 'name', type: 'string'},
                {
                    name: 'number',
                    convert: function (value, record) {
                        if (value === "") {
                            return "未设置编号"
                        } else {
                            return value;
                        }
                    }
                },
                {name: 'warehouse_type_name', mapping: 'warehouse_type',
                    convert: function (value, record) {
                        if (value === "") {
                            return ""
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'description'},
                {name: 'warehouse_type_id'},
                {name: 'is_locked'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        //角色仓库下拉框模型
        Ext.define('RoleWarehouse', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'warehouse_name', mapping: 'warehouse',
                    convert: function (value, record) {
                        if (value === "") {
                            return ""
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'is_locked'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        warehouseStore = Ext.create('Ext.data.Store', {
            autoDestroy: true,
            autoSync: true,
            model: 'Warehouse',
            proxy: {
                type: 'ajax',
                url: '/warehouse/getAllWarehouse?for_cbb=true',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            pageSize: 1000,//default:25
            autoLoad: true
        });

        //仓库类型下拉框模型
        Ext.define('WarehouseType', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'name', type: 'string'},
                {name: 'is_locked'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        customerTypeStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'CustomerType',
            proxy: {
                type: 'ajax',
                url: '/customer_type/getAllCustomerTypes?for_cbb=true',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            //pageSize : pageSize,
            autoLoad: true
        });


        //员工下拉框模型
        Ext.define('Employee', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {
                    name: 'company_name',
                    mapping: 'company',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                { name: 'number'},
                { name: 'name'},
                {name: 'quit_job'},
                {name: 'login_id'},
                {name: 'identity_card'},
                {name: 'phone'},
                {name: 'email'},
                {name: 'address'},
                {
                    name: 'department_name',
                    mapping: 'department',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'role_name',
                    mapping: 'role',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'role_id'},
                {name: 'entry_date', type: 'date', dateFormat: 'Y/m/d'},
                {name: 'quit_date', type: 'date', dateFormat: 'Y/m/d'},
                {name: 'is_locked'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        employeeStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'Employee',
            proxy: {
                type: 'ajax',
                url: '/employee/getAllEmployees?for_cbb=true',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            //pageSize: pageSize,
            autoLoad: true
        });


        //员工下拉框模型
        Ext.define('Role', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                { name: 'number'},
                { name: 'name'},
                {name: 'financial_management'},
                {name: 'sale_price_info'},
                {name: 'cross_dept_sale_order_query', type: 'string'},
                {name: 'cross_company', type: 'string'},
                {name: 'unsafe_discount_audit'},
                {name: 'discount'},
                {name: 'description'},
                {name: 'is_locked'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });


        //销售类型下拉框模型
        Ext.define('SaleType', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                { name: 'number'},
                { name: 'discount', type: 'float'},
                { name: 'name'},
                {name: 'payment_propotion', type: 'float'},
                {name: 'employee_name', mapping: 'employee', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }},
                {name: 'ab'},
                {name: 'company_name', mapping: 'company', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }},
                {name: 'company_id'},
                {name: 'description'},
                {name: 'is_locked'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        saleTypeStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'SaleType',
            proxy: {
                type: 'ajax',
                url: '/sale_type/getAllSaleTypes?for_cbb=true',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            //pageSize : pageSize,
            autoLoad: true
        });

        //销售策略下拉框模型
        Ext.define('SaleStrategy', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                { name: 'number'},
                { name: 'name'},
                { name: 'description'},
                {name: 'employee_name', mapping: 'employee', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }},
                {name: 'company_name', mapping: 'company', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }},
                {name: 'company_id'},
                {name: 'is_locked'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });


        salesStrategyStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'SaleStrategy',
            proxy: {
                type: 'ajax',
                url: '/sales_strategy/getAllSalesStrategies?for_cbb=true',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            //pageSize : pageSize,
            autoLoad: true
        });

        //销售订单Model
        Ext.define('SaleOrderModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'order_number', type: 'string'},
                {name: 'action_date', type: 'date', dateFormat: 'Y/m/d'},
                {name: 'contract_number'},
                {name: 'linkman'},
                {name: 'phone'},
                {name: 'tax_rate'},
                {name: 'delivery_address'},
                {name: 'delivery_desc'},
                {name: 'description'},
                {name: 'auditing_status'},
                {name: 'auditing_date'},
                {name: 'temp_amount'},
                {name: 'sales_id'},
                {name: 'customer_id', type: 'int'},
                {name: 'sell_dept_id'},
                {name: 'sale_type_id'},
                {name: 'sales_strategy_id'},
                {name: 'sale_returneds', mapping: 'sale_returneds',
                    convert: function (value, record) {
                        if (value.length == 0) {
                            return "否";
                        } else {
                            return "是";
                        }
                    }
                },
                {name: 'tax_rate'},
                {
                    name: 'auditor_name',
                    mapping: 'auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'audit_opinion'},
                {
                    name: 'customer_name',
                    mapping: 'customer',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'department_name',
                    mapping: 'department',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'sell_department_name',
                    mapping: 'sell_department',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'sales_name',
                    mapping: 'sales',
                    convert: function (value, record) {
                        if (value == "" || value == null) {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'employee_name', mapping: 'employee.name'},
                {
                    name: 'company_name',
                    mapping: 'company',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'deal_with_status'},
                {name: 'store_status'},
                {name: 'unsafe_discount'},
                {name: 'purchase_status' },
                {
                    name: 'delivery_employee_name',
                    mapping: 'delivery_employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'amount', type: 'float'},
                {name: 'rec_amount', type: 'float'},
                {name: 'payment_type'},
                {name: 'payment_desc'},
                {
                    name: 'sale_type',
                    convert: function (value, record) {
                        if (value == "" || value == null) {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'sales_strategy',
                    convert: function (value, record) {
                        if (value == "" || value == null) {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'is_transformed_into_purchase'},
                {name: 'created_at'},
                {name: 'updated_at'},
                {name: 'lock_version'}
            ]
        });

        //销售订单详细信息Model
        Ext.define('SaleOrderDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'product_name'},
                {name: 'product_number'},
                {name: 'number'},//也是一个产品编号与product_number重复。
                {name: 'unit'},
                {name: 'spec'},
                {name: 'quantity', type: 'int'},
                {name: 'product_id', type: 'int'},
                {name: 'unit_price'},
                {name: 'discount', type: 'float'},
                {name: 'amount', type: 'float'},
                {name: 'balance_quantity', type: 'int'},
                {name: 'ori_unit_price', mapping: 'unit_price', type: 'float'},//在新增销售订单时使用
                {name: 'sale_type_price'},//有此值就要直接使用此值，不能使用销售类型带的折扣。
                {
                    name: 'is_suit',
                    mapping: 'is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {name: 'description'},
                {name: 'lock_version'}
            ]
        });

        Ext.define('SaleOrderDetailEditModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'number', mapping: 'product.number'},
                {name: 'unit', mapping: 'product.unit'},
                {name: 'spec', mapping: 'product.spec'},
                {name: 'product_name', mapping: 'product.name'},
                {name: 'description'},
                {name: 'quantity', type: 'int'},
                {name: 'discount', type: 'float'},
                {name: 'amount', type: 'float'},
                {name: 'unit_price', type: 'float'},
                {name: 'ori_unit_price', type: 'float'},
                {name: 'product_id'},
                {name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        } else {
                            return value;
                        }
                    }
                },
                {name: 'lock_version'},
                {name: 'sale_type_price'}//有此值就要直接使用此值，不能使用销售类型带的折扣。
            ]
        });


        //销售退货订单Model
        Ext.define('SaleReturnedModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'company_name', mapping: 'company', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }  },
                {name: 'order_number'},
                {
                    name: 'sale_order_number',
                    mapping: 'sale_order',
                    convert: function (value, record) {
                        if (value == "" || value === null) {
                            return "";
                        } else {
                            return value.order_number;
                        }
                    }
                },
                {name: 'action_date', type: 'date', dateFormat: 'Y/m/d'},
                {name: 'receive_address'},
                {name: 'return_date', type: 'date', dateFormat: 'Y/m/d'},
                {name: 'amount', type: 'float'},
                {name: 'paid_amount', type: 'float'},
                {name: 'linkman'},
                {name: 'phone'},
                {name: 'tax_rate'},
                {name: 'description'},
                {name: 'auditing_status'},
                {name: 'associate_audit_opinion'},
                {name: 'associate_auditor_name',
                    mapping: 'associate_auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'warehouse_name',
                    mapping: 'warehouse',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'customer_name', mapping: 'customer.name'},
                {name: 'department_name', mapping: 'department',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'employee_name', mapping: 'employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'deal_with_status'},
                {name: 'store_status'},
                {
                    name: 'warehouse_employee_name',
                    mapping: 'warehouse_employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'contract_number',
                    mapping: 'sale_order',
                    convert: function (value, record) {
                        if (value == "" || value === null) {
                            return "";
                        } else {
                            return value.contract_number;
                        }
                    }
                },
                {
                    name: 'sale_type',
                    mapping: 'sale_order',
                    convert: function (value, record) {
                        if (value == "" || value === null) {
                            return "";
                        } else {
                            if (value.sale_type === undefined) {
                                return "";
                            } else {
                                return value.sale_type.name;
                            }
                        }
                    }
                },
                {
                    name: 'sales_strategy',
                    mapping: 'sale_order',
                    convert: function (value, record) {
                        if (value == "" || value === null) {
                            return "";
                        } else {
                            if (value.sales_strategy === undefined) {
                                return "";
                            } else {
                                return value.sales_strategy.name;
                            }
                        }
                    }
                },
                {name: 'description', mapping: 'description'},
                {name: 'lock_version'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        //销售退货订单详细信息Model
        Ext.define('SaleReturnedDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'product_name', mapping: 'product.name'},
                {name: 'product_number', mapping: 'product.number'},
                {name: 'number', mapping: 'product.number'},
                {name: 'product_id', mapping: 'product.id'},
                {name: 'discount'},
                {name: 'spec', mapping: 'product.spec'},
                {name: 'quantity', type: 'int'},
                {name: 'unit_price', type: 'float'},
                {name: 'amount', type: 'float'},
                {
                    name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {name: 'description', mapping: 'description'}
            ]
        });

        //数组，审批状态
        auditStatusStore = Ext.create('Ext.data.ArrayStore', {
            // store configs
            autoDestroy: true,
            //storeId: 'auditStatusStore',
            // reader configs
            idIndex: 0,
            fields: [
                {name: 'text', type: 'string'},
                {name: 'value', type: 'string'}
            ],
            data: auditStatusArray
        });

        //订单类型
        orderTypeArrayStore = Ext.create('Ext.data.ArrayStore', {
            // store configs
            autoDestroy: true,
            //storeId: 'auditStatusStore',
            // reader configs
            idIndex: 0,
            fields: [
                {name: 'text', type: 'string'},
                {name: 'value', type: 'string'}
            ],
            data: orderTypeArray
        });

        //数组，收付款方式 状态
        paymentTypeStore = Ext.create('Ext.data.ArrayStore', {
            // store configs
            autoDestroy: true,
            storeId: 'paymentTypeStore',
            // reader configs
            idIndex: 0,
            fields: [
                {name: 'text', type: 'string'},
                {name: 'value', type: 'string'}
            ],
            data: paymentTypeArray
        });

        //收款记录的Model
        Ext.define('Receivable', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'amount', type: 'float'},
                {name: 'order_number'},
                {name: 'seq_number', type: 'int'},
                {name: 'sales_strategy_id', type: 'int'},
                {name: 'sales_strategy_name', mapping: 'sales_strategy',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }},
                {name: 'action_date', type: 'date', dateFormat: 'Y/m/d'},
                {name: 'type_of_payment'},
                {name: 'payment_type', mapping: 'type_of_payment'},
                {name: 'description'},
                {name: 'sale_order_id'},
                {name: 'employee_name', mapping: 'employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }},
                {name: 'auditing_status'},
                {name: 'audit_opinion' },
                {name: 'created_at'},
                {name: 'updated_at'},
                {
                    name: 'new_amount',
                    type: 'float'
                },
                {
                    name: 'auditor_name',
                    mapping: 'auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'customer_id'},
                {
                    name: 'customer_name',
                    mapping: 'customer',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'sale_order_number',
                    mapping: 'sale_order',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.order_number;
                        }
                    }
                },
                {
                    name: 'sale_auditing_status',
                    mapping: 'sale_order',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.auditing_status;
                        }
                    }
                }
            ]
        });

        //收款相关的虚拟资金记录的Model
        Ext.define('Grant', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'company_name', mapping: 'company', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }  },
                {name: 'amount', type: 'float'},
                {name: 'order_number'},
                {name: 'seq_number', type: 'int'},
                {name: 'begin_date', type: 'date', dateFormat: 'Y/m/d'},
                {name: 'end_date', type: 'date', dateFormat: 'Y/m/d'},
                {name: 'description'},
                {name: 'receivable_id'},
                {name: 'receivable_order_number', mapping: 'receivable',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.order_number;
                        }
                    }
                },
                {name: 'sales_strategy_id'},
                {name: 'sales_strategy_name', mapping: 'sales_strategy',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'receivable_auditing_status', mapping: 'receivable',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.auditing_status;
                        }
                    }
                },
                {name: 'customer_name', mapping: 'receivable',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.customer.name;
                        }
                    }
                },
                {name: 'employee_name', mapping: 'employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }},
                {name: 'auditing_status'},
                {name: 'audit_opinion' },
                {name: 'created_at'},
                {name: 'updated_at'},
                {
                    name: 'new_amount',
                    type: 'float'
                },
                {
                    name: 'auditor_name',
                    mapping: 'auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                }
            ]
        });


        //收款记录的Model
        Ext.define('DeliveryOrderModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'auditing_status'},
                {name: 'deal_with_status'},
                {name: 'sale_order_number', mapping: 'sale_order.order_number'},
                {name: 'sale_order_status', mapping: 'sale_order.auditing_status'},
                {name: 'order_number'},
                {name: 'sale_action_date', mapping: 'sale_order.action_date'},
                {name: 'action_date'},
                {name: 'description'},
                {name: 'employee_name', mapping: 'employee.name'},
                {name: 'company_name', mapping: 'company', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }  },
                {name: 'department_name', mapping: 'department.name'},
                {name: 'warehouse_name',
                    mapping: 'warehouse',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'customer_name', mapping: 'customer.name'},
                {name: 'deal_with_status'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        //收款记录的Model
        Ext.define('DeliveryOrderDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'product_name', mapping: 'product.name'},
                {name: 'product_number', mapping: 'product.number'},
                {name: 'product_spec', mapping: 'product.spec'},
                {name: 'quantity', type: 'int'},
                {name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {name: 'description'}
            ]
        });

        //收款记录的Model
        Ext.define('SaleOrderNumberModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'order_number'}
            ]
        });

        saleOrderNumberStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'SaleOrderNumberModel',
            proxy: {
                type: 'ajax',
                url: '/sale_order/getSaleOrersForPurchase',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            }
        });

        //收款记录的Model
        Ext.define('SaleOrderNumberForSomeOnePurchaseModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'sale_order_id'},
                {name: 'order_number', mapping: 'sale_order.order_number'}
            ]
        });

        saleOrderNumbersForSomeOnePurchaseStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'SaleOrderNumberForSomeOnePurchaseModel',
            proxy: {
                type: 'ajax',
                url: '/purchase_order/getSaleOrdersOfPurchaseById',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            }
        });

        //采购记录的Model
        Ext.define('PurchaseOrderModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'order_number'},
                {name: 'action_date', type: 'date', dateFormat: 'Y/m/d'},
                {name: 'contract_number'},
                {name: 'linkman'},
                {name: 'phone'},
                {name: 'tax_rate'},
                {name: 'company_id'},
                {name: 'vendor_id'},
                {name: 'delivery_address'},
                {name: 'amount', type: 'float'},
                {name: 'tax_price'},
                {name: 'tax_amount', type: 'float'},
                {name: 'value_added_tax', type: 'float'},
                {name: 'paid_amount', type: 'float'},
                {name: 'description'},
                {name: 'auditing_status'},
                {name: 'audit_opinion'},
                {
                    name: 'auditor_name',
                    mapping: 'auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'vendor_name', mapping: 'vendor.name'},
                {name: 'department_name', mapping: 'department',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'company_name', mapping: 'company', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }  },
                {name: 'employee_name', mapping: 'employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'deal_with_status'},
                {name: 'store_status'},
                {
                    name: 'delivery_employee_name', mapping: 'delivery_employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'lock_version'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });


        //采购详细信息的Model
        Ext.define('PurchaseOrderDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'sale_order_number'},
                {name: 'sale_order_status'},
                {name: 'product_name'},
                {name: 'product_number'},
                {name: 'product_id'},
                {name: 'spec'},
                {name: 'quantity', type: 'int'},
                {name: 'unit_price', type: 'float'},
                {name: 'amount', type: 'float'},
                {name: 'tax_price', type: 'float'},
                {name: 'tax_amount', type: 'float'},
                {name: 'value_added_tax', type: 'float'},
                {
                    name: 'is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {name: 'balance_quantity'},
                {name: 'description'}
            ]
        });


        //入库记录的Model
        Ext.define('WarehousingEntryModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {
                    name: 'purchase_order_number',
                    mapping: 'purchase_order',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.order_number;
                        }
                    }
                },
                {
                    name: 'purchase_order_status',
                    mapping: 'purchase_order',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.auditing_status;
                        }
                    }
                },
                {name: 'order_number'},
                {name: 'auditing_status'},
                {name: 'action_date'},
                {name: 'description'},
                {name: 'company_name', mapping: 'company', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }  },
                {name: 'employee_name', mapping: 'employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'department_name', mapping: 'department',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'warehouse_name', mapping: 'warehouse',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'vendor_name', mapping: 'vendor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'description'},
                {name: 'deal_with_status'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        //入库记录详细信息的Model
        Ext.define('WarehousingEntryDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {
                    name: 'sale_order_number',
                    mapping: 'sale_order',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.order_number;
                        }
                    }
                },
                {name: 'product_name', mapping: 'product.name'},
                {name: 'product_number', mapping: 'product.number'},
                {name: 'product_spec', mapping: 'product.spec'},
                {name: 'quantity', type: 'int'},
                {
                    name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {name: 'description'}
            ]
        });

        //调拨记录详细信息的Model
        Ext.define('TransferOrderModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'order_number'},
                {name: 'action_date',
                    type: 'date',
                    dateFormat: 'Y/m/d'},
                {name: 'description'},
                {name: 'employee_name', mapping: 'employee', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }},
                {name: 'department_name', mapping: 'department', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }},
                {name: 'from_warehouse_name', mapping: 'fromWarehouse.name'},
                {name: 'to_warehouse_name', mapping: 'toWarehouse.name'},
                {name: 'from_warehouse_id'},
                {name: 'to_warehouse_id'},
                {name: 'auditing_status'},
                {name: 'audit_opinion'},
                {name: 'deal_with_status'},
                {name: 'description'},
                {
                    name: 'auditor_name',
                    mapping: 'auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });


        Ext.define('TransferOrderDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'product_id', mapping: 'product.id'},
                {name: 'product_name', mapping: 'product.name'},
                {name: 'product_number', mapping: 'product.number'},
                {name: 'product_spec', mapping: 'product.spec'},
                {name: 'quantity', type: 'int'},
                {
                    name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {name: 'description'}
            ]
        });

        //组合 记录详细信息的Model
        Ext.define('AssemblyOrderModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'order_number'},
                {name: 'action_date'},
                {name: 'description'},
                {name: 'warehouse_id'},
                {name: 'employee_name', mapping: 'employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'department_name', mapping: 'department',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'warehouse_name', mapping: 'warehouse',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'product_name', mapping: 'product',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'product_number', mapping: 'product',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.number;
                        }
                    }
                },
                {name: 'product_id', mapping: 'product',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.id;
                        }
                    }
                },
                {name: 'quantity', mapping: 'quantity'},
                {name: 'auditing_status'},
                {name: 'audit_opinion'},
                {name: 'deal_with_status'},
                {
                    name: 'auditor_name',
                    mapping: 'auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'description'},
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        //组合 记录详细信息的Model
        Ext.define('AssemblyOrderProductModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'assembly_order_id'},
                {name: 'product_id'},
                {name: 'description'},
                {name: 'name', mapping: 'product.name'},
                {name: 'product_name', mapping: 'product.name'},
                {name: 'number', mapping: 'product.number'},
                {name: 'spec', mapping: 'product.spec'},
                {name: 'product_id', mapping: 'product.id'},
                {name: 'quantity', mapping: 'quantity'},
                {
                    name: 'is_suit',
                    mapping: 'product',
                    convert: function (value, record) {
                        if (value.is_suit == "1") {
                            return "套装";
                        } else if (value.is_suit == "0") {
                            return "单品";
                        }
                    }
                },
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        Ext.define('AssemblyOrderDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'product_name', mapping: 'product.name'},
                {name: 'product_number', mapping: 'product.number'},
                {name: 'product_spec', mapping: 'product.spec'},
                {name: 'quantity', type: 'int'},
                {
                    name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {name: 'description'}
            ]
        });

        //拆分 记录详细信息的Model
        Ext.define('SeparateOrderModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'order_number'},
                {name: 'action_date'},
                {name: 'description'},
                {name: 'employee_name', mapping: 'employee.name'},
                {name: 'department_name', mapping: 'department.name'},
                {name: 'warehouse_name', mapping: 'warehouse.name'},
                {name: 'product_name', mapping: 'product.name'},
                {name: 'product_id', mapping: 'product.id'},
                {name: 'quantity', mapping: 'quantity', type: 'int'},
                {name: 'auditing_status'},
                {name: 'audit_opinion'},
                {name: 'deal_with_status'},
                {
                    name: 'auditor_name',
                    mapping: 'auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'created_at'},
                {name: 'updated_at'}
            ]
        });

        Ext.define('SeparateOrderDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'product_name', mapping: 'product.name'},
                {name: 'product_number', mapping: 'product.number'},
                {name: 'product_spec', mapping: 'product.spec'},
                {name: 'quantity', type: 'int'},
                {
                    name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {name: 'description'}
            ]
        });

        Ext.define('OpeningStockModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'company_name', mapping: 'company', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }  },
                {name: 'order_number'},
                {name: 'linkman'},
                {name: 'phone'},
                {name: 'description'},
                {name: 'amount', type: 'float'},
                {name: 'tax_amount', type: 'float'},
                {name: 'tax_rate', type: 'float'},
                {name: 'value_added_tax', type: 'float'},
                {name: 'action_date',
                    type: 'date',
                    dateFormat: 'Y/m/d'},
                {name: 'auditing_status'},
                {name: 'audit_opinion'},
                {name: 'auditor_name', mapping: 'auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'warehouse_name', mapping: 'warehouse',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'warehouse_id'},
                {name: 'vendor_name', mapping: 'vendor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'vendor_id'},
                {name: 'department_name', mapping: 'department',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }},
                {name: 'employee_name', mapping: 'employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'deal_with_status'},
                {name: 'created_at'},
                {name: 'updated_at'},
                {name: 'lock_version'}
            ]
        });

        Ext.define('OpeningStockDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'sale_order_number'},
                {name: 'sale_order_status'},
                {name: 'product_name', mapping: 'product.name'},
                {name: 'product_number', mapping: 'product.number'},
                {name: 'product_spec', mapping: 'product.spec'},
                {name: 'product_id'},
                {name: 'quantity', type: 'int'},
                {name: 'unit_price', type: 'float'},
                {name: 'amount', type: 'float'},
                {name: 'tax_price', type: 'float'},
                {name: 'tax_amount', type: 'float'},
                {name: 'value_added_tax', type: 'float'},
                {
                    name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {name: 'balance_quantity'},
                {name: 'description'}
            ]
        });

        Ext.define('InventoryModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'order_number'},
                {
                    name: 'action_date'
                },
                {
                    name: 'description'
                },
                {
                    name: 'auditing_status'
                },
                {
                    name: 'audit_opinion'
                },
                {
                    name: 'auditor_name',
                    mapping: 'auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'vendor_name',
                    mapping: 'vendor.name'
                },
                {
                    name: 'department_name',
                    mapping: 'department',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'employee_name',
                    mapping: 'employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'warehouse_name',
                    mapping: 'warehouse.name'
                },
                {
                    name: 'deal_with_status'
                },
                {
                    name: 'description'
                },
                {name: 'created_at'},
                {name: 'updated_at'},
                {name: 'lock_version'}
            ]
        });

        Ext.define('InventoryDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {
                    name: 'product_name',
                    mapping: 'product.name'
                },
                {
                    name: 'product_number',
                    mapping: 'product.number'
                },
                {
                    name: 'product_spec',
                    mapping: 'product.spec'
                },
                {
                    name: 'quantity',
                    type: 'int'
                },
                {
                    name: 'gl_quantity',
                    type: 'int'
                },
                {
                    name: 'unit_price',
                    type: 'float'
                },
                {
                    name: 'amount',
                    type: 'float'
                },
                {
                    name: 'description'
                },
                {
                    name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                }
            ]
        });


        Ext.define('SysAction', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'name'}
            ]
        });

        sysActionStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'SysAction',
            proxy: {
                type: 'ajax',
                url: '/admin/getAllSysActions',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            pageSize: 10000
        });

        Ext.define('SysController', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'name'}
            ]
        });

        sysControllerStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'SysController',
            proxy: {
                type: 'ajax',
                url: '/admin/getAllSysControllers',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            pageSize: 200
        });

        Ext.define('SysPrivilegeDetail', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'name'},
                {name: 'sys_controller_id', type: 'int'},
                {name: 'sys_action_id', type: 'int'},
                {name: 'controller_name', mapping: 'sys_controller', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }},
                {name: 'action_name', mapping: 'sys_action', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }},
                {name: 'params'},
                {name: 'coupling_interface'},
                {name: 'sub_type'},
                {name: 'description'},
                {name: 'created_at'},
                {name: 'is_locked'}
            ]
        });


        Ext.define('Privilege', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'name'},
                {name: 'number'},
                {name: 'sys_controller_id', type: 'int'},
                {name: 'sys_action_id', type: 'int'},
                {name: 'description'},
                {name: 'parent_id', type: 'int'},
                {name: 'module_id', mapping: 'parent_id'}
            ]
        });

        moduleStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'Privilege',
            proxy: {
                type: 'ajax',
                url: '/admin/getAllModules',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            pageSize: 100
        });

        Ext.define('RolesPrivilegeDetail', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'name', mapping: 'privilege_detail.name'},
                {name: 'description', mapping: 'privilege_detail.description'},
                {name: 'is_locked'}
            ]
        });


        Ext.define('ProductTypeModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'name'},
                {name: 'description'},
                {name: 'is_locked' },
                {name: 'created_at' },
                {name: 'updated_at' }
            ]
        });

        productTypeStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'ProductTypeModel',
            proxy: {
                type: 'ajax',
                url: "/product_type/getAllProductTypes",
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            autoLoad: true
        });


        Ext.define('BrandModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {name: 'name'},
                {name: 'description'},
                {name: 'vendor_name', mapping: 'vendor', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }
                },
                {name: 'vendor_id'},
                {name: 'is_locked'},
                {name: 'created_at' },
                {name: 'updated_at' }
            ]
        });

        brandStore = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model: 'BrandModel',
            proxy: {
                type: 'ajax',
                url: "/brand/getAllBrands?for_cbb=true",
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalProperty'// 数据集记录总数
                }
            },
            autoLoad: true
        });

        Ext.define('LoanOrderModel', {
            extend: 'Ext.data.Model',
            fields: [
                {
                    name: 'id'
                },
                {
                    name: 'order_number'
                },
                {name: 'action_date', type: 'date', dateFormat: 'Y/m/d'},
                {name: 'contract_number'},
                {name: 'linkman'},
                {name: 'phone'},
                {name: 'delivery_address'},
                {name: 'description'},
                {name: 'auditing_status'},
                {
                    name: 'auditor_name',
                    mapping: 'auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'audit_opinion'
                },
                {name: 'customer_id'},
                {name: 'sales_id'},
                {name: 'employee_id'},
                {name: 'department_id'},
                {
                    name: 'customer_name',
                    mapping: 'customer.name'
                },
                {
                    name: 'department_name',
                    mapping: 'department',
                    convert: function (value, record) {
                        if (value == "" || value == null) {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'sales_name',
                    mapping: 'sales',
                    convert: function (value, record) {
                        if (value == "" || value == null) {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'employee_name',
                    mapping: 'employee',
                    convert: function (value, record) {
                        if (value == "" || value == null) {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'deal_with_status'
                },
                {
                    name: 'store_status'
                },
                {
                    name: 'return_status'
                },
                {
                    name: 'amount',
                    type: 'float'
                },
                {
                    name: 'sub_type',
                    convert: function (value, record) {
                        if (value == "" || value == null) {
                            return "";
                        } else {
                            return value;
                        }
                    }
                },
                {
                    name: 'delivery_employee_name',
                    mapping: 'delivery_employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {name: 'created_at'},
                {name: 'updated_at'},
                {name: 'lock_version'}
            ]
        });

        Ext.define('LoanOrderDetailEditModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {
                    name: 'number',
                    mapping: 'product.number'
                },
                {
                    name: 'product_name',
                    mapping: 'product.name'
                },
                {
                    name: 'spec',
                    mapping: 'product.spec'
                },
                {
                    name: 'unit',
                    mapping: 'product.unit'
                },
                {
                    name: 'description'
                },
                {
                    name: 'quantity'
                },
                {
                    name: 'product_id'
                },
                {
                    name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {
                    name: 'description'
                }
            ]
        });

        Ext.define('LoanOrderDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {
                    name: 'product_name'
                },
                {
                    name: 'product_number'
                },
                {
                    name: 'spec'
                },
                {
                    name: 'quantity',
                    type: 'int'
                },
                {
                    name: 'balance_quantity',
                    type: 'int'
                },
                {
                    name: 'is_suit',
                    mapping: 'is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {
                    name: 'description'
                }
            ]
        });

        Ext.define('LoanDeliveryModel', {
            extend: 'Ext.data.Model',
            fields: [
                {
                    name: 'id'
                },
                {
                    name: 'auditing_status'
                },
                {
                    name: 'deal_with_status'
                },
                {
                    name: 'loan_number',
                    mapping: 'loan.order_number'
                },
                {
                    name: 'loan_status',
                    mapping: 'loan.auditing_status'
                },
                {
                    name: 'order_number'
                },
                {
                    name: 'loan_action_date',
                    mapping: 'loan.action_date'
                },
                {
                    name: 'action_date'
                },
                {
                    name: 'description'
                },
                {
                    name: 'employee_name',
                    mapping: 'employee.name'
                },
                {
                    name: 'department_name',
                    mapping: 'department.name'
                },
                {
                    name: 'warehouse_name',
                    mapping: 'warehouse.name'
                },
                {
                    name: 'customer_name',
                    mapping: 'customer.name'
                },
                {
                    name: 'deal_with_status'
                },
                {
                    name: 'created_at'
                },
                {
                    name: 'updated_at'
                }
            ]
        });

        Ext.define('LoanDeliveryDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {
                    name: 'id'
                },
                {
                    name: 'product_name',
                    mapping: 'product.name'
                },
                {
                    name: 'product_number',
                    mapping: 'product.number'
                },
                {
                    name: 'product_spec',
                    mapping: 'product.spec'
                },
                {
                    name: 'quantity',
                    type: 'int'
                },
                {
                    name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {
                    name: 'description'
                }
            ]
        });

        Ext.define('LoanReturnedModel', {
            extend: 'Ext.data.Model',
            fields: [
                {
                    name: 'id'
                },
                {name: 'company_name', mapping: 'company', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }  },
                {
                    name: 'order_number'
                },
                {
                    name: 'loan_order_number',
                    mapping: 'loan',
                    convert: function (value, record) {
                        if (value == "" || value === null) {
                            return "";
                        } else {
                            return value.order_number;
                        }
                    }
                },
                {
                    name: 'action_date'
                },
                {
                    name: 'description'
                },
                {
                    name: 'auditing_status'
                },
                {
                    name: 'audit_opinion'
                },
                {
                    name: 'auditor_name',
                    mapping: 'auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'customer_name',
                    mapping: 'customer.name'
                },
                {
                    name: 'department_name',
                    mapping: 'department.name'
                },
                {
                    name: 'employee_name',
                    mapping: 'employee.name'
                },
                {
                    name: 'deal_with_status'
                },
                {
                    name: 'store_status'
                },
                {
                    name: 'warehouse_employee_name',
                    mapping: 'warehouse_employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'warehouse_name',
                    mapping: 'warehouse',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'created_at'
                },
                {
                    name: 'updated_at'
                }
            ]
        });

        Ext.define('LoanReturnedDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {
                    name: 'id'
                },
                {
                    name: 'product_name',
                    mapping: 'product.name'
                },
                {
                    name: 'product_number',
                    mapping: 'product.number'
                },
                {
                    name: 'spec',
                    mapping: 'product.spec'
                },
                {
                    name: 'quantity',
                    type: 'int'
                },
                {
                    name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {
                    name: 'description',
                    mapping: 'product.description'
                }
            ]
        });

        //
        Ext.define('PurchaseReturnedModel', {
            extend: 'Ext.data.Model',
            fields: [
                {
                    name: 'id'
                },
                {name: 'company_name', mapping: 'company', convert: function (value, record) {
                    if (value == "") {
                        return "";
                    } else {
                        return value.name;
                    }
                }  },
                {
                    name: 'order_number'
                },
                {
                    name: 'purchase_order_number',
                    mapping: 'purchase_order',
                    convert: function (value, record) {
                        if (value == "" || value === null) {
                            return "";
                        } else {
                            return value.order_number;
                        }
                    }
                },
                {
                    name: 'return_date'
                },
                {
                    name: 'action_date'
                },
                {
                    name: 'amount',
                    type: 'float'
                },
                {
                    name: 'paid_amount',
                    type: 'float'
                },
                {
                    name: 'description'
                },
                {
                    name: 'auditing_status'
                },
                {
                    name: 'associate_audit_opinion'
                },
                {
                    name: 'associate_auditor_name',
                    mapping: 'associate_auditor',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'vendor_name',
                    mapping: 'vendor.name'
                },
                {
                    name: 'department_name',
                    mapping: 'department.name'
                },
                {
                    name: 'employee_name',
                    mapping: 'employee.name'
                },
                {
                    name: 'deal_with_status'
                },
                {
                    name: 'store_status'
                },
                {
                    name: 'delivery_employee_name',
                    mapping: 'warehouse_employee',
                    convert: function (value, record) {
                        if (value == "") {
                            return "";
                        } else {
                            return value.name;
                        }
                    }
                },
                {
                    name: 'created_at'
                },
                {
                    name: 'updated_at'
                }
            ]
        });

        Ext.define('LoanReturnedDetailModel', {
            extend: 'Ext.data.Model',
            fields: [
                {
                    name: 'id'
                },
                {
                    name: 'product_name',
                    mapping: 'product.name'
                },
                {
                    name: 'product_number',
                    mapping: 'product.number'
                },
                {
                    name: 'spec',
                    mapping: 'product.spec'
                },
                {
                    name: 'quantity',
                    type: 'int'
                },
                {
                    name: 'unit_price',
                    type: 'float'
                },
                {
                    name: 'amount',
                    type: 'float'
                },
                {
                    name: 'is_suit',
                    mapping: 'product.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                },
                {
                    name: 'description',
                    mapping: 'product.description'
                }
            ]
        });

        //for separate,assembly
        Ext.define('SubProductModel', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id'},
                {
                    name: 'product_id',
                    mapping: 'component.id'
                } ,
                {
                    name: 'number',
                    mapping: 'component.number'
                },
                {
                    name: 'name',
                    mapping: 'component.name'
                },
                {
                    name: 'description'
                },
                {
                    name: 'quantity',
                    type: 'int'
                },
                {
                    name: 'spec',
                    mapping: 'component.spec'
                },
                {
                    name: 'unit',
                    mapping: 'component.unit'
                },
                {
                    name: 'is_suit',
                    mapping: 'component.is_suit',
                    convert: function (value, record) {
                        if (value == "1") {
                            return "套装";
                        } else if (value == "0") {
                            return "单品";
                        }
                    }
                }
            ]
        });

    });
</script>
</head>
<body>
<%= javascript_include_tag "application.js" %>
</body>
</html>